package com.taplinker.client.im.activity;

import java.io.File;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.List;
import java.util.Set;
import java.util.UUID;

import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.provider.MediaStore;
import android.text.Html;
import android.text.Html.ImageGetter;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.view.WindowManager.LayoutParams;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;

import com.taplinker.client.AppConfigFactory;
import com.taplinker.client.R;
import com.taplinker.client.core.LocalFileManager;
import com.taplinker.client.core.RecordingManager;
import com.taplinker.client.im.adapter.ChatListAdapter;
import com.taplinker.client.im.adapter.GridViewAdapter;
import com.taplinker.client.im.domain.ImDataCenter;
import com.taplinker.client.im.domain.ImMessageHandler;
import com.taplinker.client.im.protocol.TapLinkerConversation;
import com.taplinker.client.im.util.SmileyParser;
import com.taplinker.client.widget.CircleFlowIndicator;
import com.taplinker.client.widget.PullToRefreshListView;
import com.taplinker.client.widget.ViewFlow;
import com.taplinker.core.util.ImageUtil;
import com.winona.ui.ProductActivity;

public class ChatActivity extends Activity implements OnClickListener {
	private static final String TAG = "com.taplinker.client.im.activity.ChatActivity";
	/**
	 * 根据输入框内的缓存表情的表情进行字符替换
	 */
	private static final Hashtable<CharSequence, String> smile = new Hashtable<CharSequence, String>();
	/**
	 * 缓存输入框内的表情
	 */
	List<CharSequence> cs = new ArrayList<CharSequence>();
	private static final int REQUEST_CODE_CAMERA = 1;
	private static final int REQUEST_CODE_ALBUM = 2;
	private static final int REQUEST_CODE_BACK = 3;
	private static final int REQUEST_CODE_FILE = 4;

	private View optionSelectBar;

	private View optionFaceBt, optionProBt;

	private View faceBar;

	private View photoCameraBt;
	private View photoAlbumBt;

	private View closeRemind;
	private TextView close_text;
	private ImageView close;

	private View inputBar;
	private Button inputTypeBt;
	private Button inputMoreBt;
	private EditText inputEditEt;
	private Button inputRecordingBt;
	private Button inputSendBt;

	private Intent intent;

	private ImageView chat_back;
	private TextView title;
	private ImageButton con_close;
	private ImageButton Out_records;

	private ViewFlow faceViewFlow;
	private CircleFlowIndicator faceIndic;

	private PopupWindow mPopupWindow;
	private PopupWindow optionPopwin;

	protected ChatListAdapter chatListAdapter;
	private FaceViewFlowAdapter faceFlowAdapter;

	// 表情相关，表情加载和处理方式存在问题，需要以后调整
	private Set<Integer> index_set = new HashSet<Integer>();
	private Set<Integer> delete_set = new HashSet<Integer>();

	private boolean isTextType = true; // 输入方式类型:true,文本输入;false:语音

	public PullToRefreshListView refreshView;

	private TapLinkerConversation conversation;

	protected int countOfFirstLoad;
	private boolean isPubQueue = false;

	private String imagePath = "";

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.chat_sdk);
		findView();

		init();
	}

	private void init() {
		conversation = ImDataCenter.getInstance().getConversation();
		int size = conversation.getUnreadMessages()
				- conversation.getMessages().size();
		ImDataCenter.getInstance().getConversationByPage(
				conversation.getMessages().size(), size, conversation);
		if (conversation.getQueueType() == TapLinkerConversation.PRIVATE_QUEUE) {
			isPubQueue = true;
			ImDataCenter.getInstance().getPrivateConversation(conversation);
		}
		// initOptionPopWin();
		initTitlebar();
		initChatContent();
		initInputBar();
		initMoreOption();
		initfaceBar();
		initPhotoOption();

		initset();

	}

	private void findView() {

		title = (TextView) findViewById(R.id.chat_title);
		con_close = (ImageButton) findViewById(R.id.conver_close);
		Out_records = (ImageButton) findViewById(R.id.out_records);

		// 输入bar
		inputBar = (View) findViewById(R.id.input_bar); // 输入类型
		inputTypeBt = (Button) findViewById(R.id.input_type_bt); // 输入类型
		inputMoreBt = (Button) findViewById(R.id.input_more_bt); // 更多
		inputEditEt = (EditText) findViewById(R.id.input_edit_et); // 文本输入
		inputRecordingBt = (Button) findViewById(R.id.input_recording_bt); // 语音按钮
		inputSendBt = (Button) findViewById(R.id.input_send_bt); // 发送
		// 更多输入工具选择区
		optionSelectBar = findViewById(R.id.option_select_bar);

		optionFaceBt = findViewById(R.id.option_face_bt); // 表情
		optionProBt = findViewById(R.id.photo_pro_bt); // 产品
		// 图片选择方式

		photoCameraBt = findViewById(R.id.photo_camera_bt); // 照相
		photoAlbumBt = findViewById(R.id.option_photo_bt); // 相册

		// 表情
		faceBar = findViewById(R.id.face_bar);
		faceViewFlow = (ViewFlow) findViewById(R.id.face_viewflow);
		faceIndic = (CircleFlowIndicator) findViewById(R.id.face_viewflowindic);

		chat_back = (ImageView) findViewById(R.id.chat_backs);
		conversation = new TapLinkerConversation();
	}

	@Override
	public void onClick(View v) {

	}

	protected void initTitlebar() {
		String userName = conversation.getCustomerName();

		userName = userName.substring(userName.lastIndexOf('_') + 1);

		title.setText(userName);
		Out_records.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent intent = new Intent(ChatActivity.this,
						ChatIMQueueActivity.class);
				intent.putExtra("public_queue", !isPubQueue);
				startActivity(intent);
			}
		});
		con_close.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent intent = new Intent(ChatActivity.this,
						FinishChatActivity.class);
				// intent.putExtra("public_queue", !isPubQueue);
				startActivity(intent);
			}
		});
		chat_back.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent intent = new Intent(ChatActivity.this,
						IMQueueActivity.class);
				startActivity(intent);
			}
		});
		optionProBt.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent intent = new Intent(ChatActivity.this,
						ProductActivity.class);
				startActivity(intent);
			}
		});

	}

	@Override
	protected void onNewIntent(Intent intent) {
		super.onNewIntent(intent);
		setIntent(intent);
		conversation = ImDataCenter.getInstance().getConversation();
		init();
	}

	/**
	 * 更多输入方式的选择
	 */
	protected void initMoreOption() {

		optionFaceBt.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				resetViewStatus(FACE_SHOW);
			}
		});

	}

	/**
	 * 照相初始化
	 */
	protected void initPhotoOption() {
		photoCameraBt.setOnClickListener(new OnClickListener() {

			@TargetApi(Build.VERSION_CODES.CUPCAKE)
			@Override
			public void onClick(View v) {
				resetViewStatus(PHOTO_HIDE);
				Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
				File f = new File(LocalFileManager.getInstance().getCameraDir());
				if (!f.exists()) {
					f.mkdirs();
				}
				if (!f.isDirectory()) {
					f.delete();
					f.mkdirs();
				}
				String tmpName = UUID.randomUUID().toString() + ".jpg";
				imagePath = LocalFileManager.getInstance().getCameraDir() + "/"
						+ tmpName;
				File out = new File(f, tmpName);
				Uri uri = Uri.fromFile(out);
				intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
				startActivityForResult(intent, REQUEST_CODE_CAMERA);
			}
		});

		photoAlbumBt.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				resetViewStatus(PHOTO_HIDE);
				Intent intent = new Intent();
				intent.setType("image/*");
				intent.setAction(Intent.ACTION_GET_CONTENT);
				startActivityForResult(intent, REQUEST_CODE_ALBUM);
			}
		});

	}

	protected void initChatContent() {
		chatListAdapter = new ChatListAdapter(this, conversation.getMessages());

		refreshView = (PullToRefreshListView) findViewById(R.id.frame_listview_tweet);

		refreshView.setAdapter(chatListAdapter);
		refreshView
				.setOnRefreshListener(new PullToRefreshListView.OnRefreshListener() {
					@Override
					public void onRefresh() {
						refreshView.setPrevious(chatListAdapter.getCount());
						ImDataCenter.getInstance()
								.getConversationByPage(
										conversation.getMessages().size(),
										conversation);
					}
				});
		refreshView.setOnTouchListener(new View.OnTouchListener() {

			@Override
			public boolean onTouch(View v, MotionEvent event) {
				// areaOnTouchListener();
				return false;
			}
		});
		refreshView.setOnScrollListener(new AbsListView.OnScrollListener() {

			@Override
			public void onScrollStateChanged(AbsListView view, int scrollState) {
				refreshView.onScrollStateChanged(view, scrollState);

				// 数据为空--不用继续下面代码了
				if (chatListAdapter.isEmpty()) {
					return;
				}
				if (view.getLastVisiblePosition() == view
						.getPositionForView(findViewById(R.id.bottom_area))) {
					refreshView
							.setTranscriptMode(ListView.TRANSCRIPT_MODE_ALWAYS_SCROLL);
				} else {
					refreshView
							.setTranscriptMode(ListView.TRANSCRIPT_MODE_DISABLED);
				}
			}

			public void onScroll(AbsListView view, int firstVisibleItem,
					int visibleItemCount, int totalItemCount) {
				refreshView.onScroll(view, firstVisibleItem, visibleItemCount,
						totalItemCount);
			}
		});
	}

	Handler handlerTimeout = new Handler();
	Runnable runnableTimeout = new Runnable() {
		public void run() {
			hideRecordingPopup();
			showRecordingPopup(R.layout.recording_time_out);
			checkRecording(true);
		}
	};

	/**
	 * 输入方式
	 */
	protected void initInputBar() {
		/**
		 * 输入框监听 获得焦点：底部区全部隐藏；失去焦点：输入法隐藏、产品信息显示
		 */
		inputEditEt.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				resetViewStatus(KEYBOARD_SHOW);
			}
		});

		/**
		 * 录音按钮触摸监听 按下：底部区全部隐藏、输入法隐藏、录音弹窗显示、产品信息显示；弹起：录音弹窗隐藏、产品信息显示
		 */
		inputRecordingBt.setOnTouchListener(new OnTouchListener() {
			public boolean onTouch(View v, MotionEvent event) {
				if (handlerTimeout == null || runnableTimeout == null) {
					return false;
				}
				switch (event.getAction()) {
				// 按下
				case MotionEvent.ACTION_DOWN:
					faceBar.setVisibility(View.GONE);

					optionSelectBar.setVisibility(View.GONE);
					showRecordingPopup(R.layout.recording_pop_win);

					Log.d(TAG, "--->start recording...");
					RecordingManager.getInstance().recording(ChatActivity.this);
					handlerTimeout.postDelayed(runnableTimeout,
							RecordingManager.TIME_LONGEST);
					break;
				// 弹起
				case MotionEvent.ACTION_UP:
					handlerTimeout.removeCallbacks(runnableTimeout);
					checkRecording(false);

					break;
				default:
					break;
				}
				return false;
			}

		});

		/**
		 * 输入类型切换监听 语音：输入法隐藏、底部区隐藏、输入录音按钮显示 文本：底部区隐藏、输入文本按钮显示
		 */
		inputTypeBt.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				resetInputType(!isTextType);
			}
		});

		/**
		 * 发送按钮监听 语音:隐藏发送按钮
		 */
		inputSendBt.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				String content = inputEditEt.getText().toString();
				if (TextUtils.isEmpty(content)) {
					Toast.makeText(ChatActivity.this, "内容不能为空，请重新输入。",
							Toast.LENGTH_SHORT).show();
				} else {
					for (CharSequence c : cs) {
						content = content.replaceFirst(c.toString(),
								smile.get(c));
					}
					cs.clear();
					smile.clear();
					inputEditEt.setText("");
					// 发文本消息
					ImMessageHandler.getInstance().sendTextMessage(content,
							conversation);
				}
			}
		});

		/**
		 * 更多输入工具监听 底部已显示：输入法隐藏、底部区隐藏、产品信息显示 底部已隐藏：产品信息隐藏、底部区显示
		 */
		inputMoreBt.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (optionSelectBar.getVisibility() == View.VISIBLE) {
					resetViewStatus(OPTIONS_HIDE);
				} else {
					resetViewStatus(OPTIONS_SHOW);
				}
			}
		});

		// 初始输入类型为文本
		resetInputType(true);
	}

	private void checkRecording(boolean showDelayed) {
		String recPath = RecordingManager.getInstance().stopRec(this);
		if (!TextUtils.isEmpty(recPath)) {
			File file = new File(recPath);
			if (file.exists()) {
				ImMessageHandler.getInstance().sendRecordMessage(this, file,
						conversation);
			}
		} else {
			showDelayed = true;
			hideRecordingPopup();
			showRecordingPopup(R.layout.recording_error_win);
		}
		if (!showDelayed) {
			hideRecordingPopup();
			return;
		}
		new Handler().postDelayed(new Runnable() {

			@Override
			public void run() {
				hideRecordingPopup();
			}
		}, 2000);
	}

	/**
	 * 重置输入类型
	 * 
	 * @param isTextType
	 */
	protected void resetInputType(boolean isTextType) {
		this.isTextType = isTextType;
		if (isTextType) {
			inputTypeBt.setSelected(false);
			inputRecordingBt.setVisibility(View.GONE);
			inputEditEt.setVisibility(View.VISIBLE);
			inputSendBt.setVisibility(View.VISIBLE);
		} else {
			inputTypeBt.setSelected(true);
			// hideKeyboard();
			inputEditEt.setVisibility(View.GONE);
			inputSendBt.setVisibility(View.GONE);
			optionSelectBar.setVisibility(View.GONE);
			faceBar.setVisibility(View.GONE);

			inputRecordingBt.setVisibility(View.VISIBLE);
		}

	}

	/**
	 * 初始化表情
	 */
	protected void initfaceBar() {
		faceFlowAdapter = new FaceViewFlowAdapter(this);
		faceViewFlow.setAdapter(faceFlowAdapter);
		faceIndic.setFillColor(Color.BLACK);
		faceIndic.setStrokeColor(Color.GRAY);
		faceViewFlow.setFlowIndicator(faceIndic);
	}

	protected ImageGetter imageGetter = new ImageGetter() {

		@Override
		public Drawable getDrawable(String source) {
			int id = Integer.parseInt(source);
			Drawable d = getResources().getDrawable(id);
			d.setBounds(0, 0, d.getIntrinsicWidth() / 2,
					d.getIntrinsicHeight() / 2);
			return d;
		}
	};

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		if (resultCode == RESULT_OK) {
			switch (requestCode) {
			case REQUEST_CODE_CAMERA:
				startEditPic();
				break;
			case REQUEST_CODE_ALBUM:
				Uri uri = data.getData();
				if (uri != null) {
					onGetPhotoData(uri);
				}
				break;
			case REQUEST_CODE_BACK:
				String path = data.getStringExtra("MinPath");
				if (!TextUtils.isEmpty(path)) {
					File file = new File(path);
					if (file != null && file.exists()) {
						ImMessageHandler.getInstance().sendImageMessage(file,
								conversation);
					}
				}
				break;

			default:
				break;
			}
		}
		super.onActivityResult(requestCode, resultCode, data);
	}

	@Override
	protected void onResume() {
		super.onResume();
		// handleMessage("");
	}

	/**
	 * 聊天内容faceViewFlow组件适配器
	 * 
	 */
	class FaceViewFlowAdapter extends BaseAdapter {
		protected Context context = null;

		public FaceViewFlowAdapter(Context context) {
			this.context = context;
		}

		public int getCount() {
			float all = (float) SmileyParser.DEFAULT_SMILEY_RES_IDS.length;
			return (int) Math.round(all / SmileyParser.PERPAGE_IMAGE_SIZE);
		}

		public Object getItem(int position) {
			return position;
		}

		public long getItemId(int position) {
			return position;
		}

		public View getView(int position, View convertView, ViewGroup parent) {
			GridView gridView;
			if (convertView == null) {
				gridView = new GridView(context);
				convertView = gridView;
				gridView.setNumColumns(6);
				gridView.setVerticalSpacing(20);
				gridView.setHorizontalSpacing(8);
				gridView.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
				gridView.setColumnWidth(60);
				gridView.setGravity(Gravity.CENTER);
				int _10dp = ImageUtil.dip2px(context, 10);
				gridView.setPadding(_10dp, 0, _10dp, 0);
				convertView.setTag(gridView);
			} else {
				gridView = (GridView) convertView.getTag();
			}

			GridViewAdapter adapter = new GridViewAdapter(context, position);
			gridView.setAdapter(adapter);
			final int pos = position;
			gridView.setOnItemClickListener(new OnItemClickListener() {

				@Override
				public void onItemClick(AdapterView<?> parent, View view,
						int position, long id) {
					if (index_set.contains(position)) {// 表情
						if (position > 17) {
							position -= 1;
						}
						String img = "<img src='"
								+ SmileyParser.DEFAULT_SMILEY_RES_IDS[position
										+ (pos * 18)] + "'/>";
						CharSequence css = Html
								.fromHtml(img, imageGetter, null);

						int index = inputEditEt.getSelectionStart();
						inputEditEt.getText().insert(index, css);
						cs.add(css);
						int index2 = position + (pos * 17) + 1;
						smile.put(css, "<" + index2 + ">");
					} else if (delete_set.contains(position)) {// 删除
						int end = inputEditEt.getSelectionStart();
						if (end > 0) {
							String temp = inputEditEt.getText()
									.subSequence(end - 1, end).toString();
							for (int i = cs.size() - 1; i > -1; i--) {
								if (temp.equals(cs.get(i).toString())) {
									smile.remove(cs.get(i));
									cs.remove(i);
									break;
								}
							}
							inputEditEt.getText().delete(end - 1, end);
						}
					}
				}
			});
			return gridView;
		}

	}

	protected void initset() {
		for (int i = 0; i < 17; i++) {
			index_set.add(i);
		}
		for (int i = 18; i < 35; i++) {
			index_set.add(i);
		}
		for (int i = 36; i < 51; i++) {
			index_set.add(i);
		}
		delete_set.add(17);
		delete_set.add(35);
		delete_set.add(53);
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			if (faceBar.getVisibility() == View.VISIBLE

			|| optionSelectBar.getVisibility() == View.VISIBLE) {
				resetViewStatus(NORMAL);
				return false;
			}
			if (RecordingManager.getInstance().isPlaying()) {
				RecordingManager.getInstance().stopRec(this);
			}
			return super.onKeyDown(keyCode, event);

		}
		return false;
	}

	protected void onGetPhotoData(Uri uri) {
		if (uri.toString().startsWith("file:")) {
			imagePath = uri.toString().substring("file:///".length());
		} else if (uri.toString().startsWith("content://")) {
			String[] projection = { MediaStore.Images.Media.DATA };
			Cursor cursor = getContentResolver().query(uri, projection, null,
					null, null);
			cursor.moveToFirst();
			int index = cursor
					.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
			imagePath = cursor.getString(index);
		} else {
			imagePath = uri.toString();
		}
		startEditPic();
	}

	private void startEditPic() {
		if (!TextUtils.isEmpty(imagePath)) {
			Intent it = new Intent(this, PickPictureActivity.class);
			it.putExtra("ImagePath", imagePath);
			startActivityForResult(it, REQUEST_CODE_BACK);
		}
	}

	/**
	 * 显示弹窗
	 */
	protected void showRecordingPopup(int loyoutId) {
		if (mPopupWindow == null) {
			View popWinView = LayoutInflater.from(this).inflate(loyoutId, null);
			mPopupWindow = new PopupWindow(popWinView,
					LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		}
		mPopupWindow.showAtLocation(findViewById(R.id.main_view_area),
				Gravity.CENTER, 0, 0);

	}

	/**
	 * 隐藏录音弹窗
	 */
	protected void hideRecordingPopup() {
		if (mPopupWindow != null) {
			mPopupWindow.dismiss();
			mPopupWindow = null;
		}

	}

	// @Override
	// public void handleMessage(String type) {
	// super.handleMessage(type);
	// if (type.equals(conversation.getId())) {
	// chatListAdapter.notifyDataSetChanged();
	// refreshView.setSelection(0);
	// if (conversation.getQueueType() == TapLinkerConversation.PRIVATE_QUEUE) {
	//
	// ImDataCenter.getInstance().getPrivateConversation(conversation);
	// isPubQueue = false;
	//
	// }
	// if ("FINISH".equals(conversation.getStatus())) {
	// finish();
	// }
	// }
	// if (type.equals(ImDataCenter.REFRESH_FINISH + conversation.getId())) {
	// refreshView.onRefreshComplete();
	// refreshView.moreRefresh();
	// chatListAdapter.notifyDataSetChanged();
	// refreshView.setSelection(0);
	// }
	// if (type.equals(ImDataCenter.MESSAGE_FINISH)) {
	// chatListAdapter.notifyDataSetChanged();
	// }
	// if (type.equals(ImDataCenter.MESSAGE_RECEIVE + conversation.getId())) {
	// ImDataCenter.getInstance().getPrivateConversation(conversation);
	// chatListAdapter.notifyDataSetChanged();
	// }
	//
	// }

	// View状态
	private static final int NORMAL = 0;
	private static final int KEYBOARD_SHOW = 1;
	private static final int KEYBOARD_HIDE = 2;
	private static final int VOICE = 3;
	private static final int OPTIONS_SHOW = 4;
	private static final int OPTIONS_HIDE = 5;
	private static final int PHOTO_SHOW = 6;
	private static final int PHOTO_HIDE = 7;
	private static final int FACE_SHOW = 8;
	private static final int FACE_HIDE = 9;
	private static final int MODULE_SHOW = 10;
	private static final int MODULE_HIDE = 11;

	private void resetViewStatus(int status) {
		switch (status) {
		// 显示输入法面板
		case KEYBOARD_SHOW:
			// showKeyboard();
			resetInputType(true);

			inputMoreBt.setSelected(false);
			faceBar.setVisibility(View.GONE);

			optionSelectBar.setVisibility(View.GONE);

			break;
		// 隐藏输入法面板
		case KEYBOARD_HIDE:
			// hideKeyboard();
			break;
		// 录音
		case VOICE:
			resetInputType(false);
			faceBar.setVisibility(View.GONE);

			optionSelectBar.setVisibility(View.GONE);

			break;
		// 显示更多选项
		case OPTIONS_SHOW:
			// hideKeyboard();
			resetInputType(true);

			inputMoreBt.setSelected(true);
			faceBar.setVisibility(View.GONE);

			optionSelectBar.setVisibility(View.VISIBLE);

			break;
		// 隐藏更多选项
		case OPTIONS_HIDE:

			inputMoreBt.setSelected(false);
			faceBar.setVisibility(View.GONE);

			optionSelectBar.setVisibility(View.GONE);

			break;
		// 显示照相选项
		case PHOTO_SHOW:

			optionSelectBar.setVisibility(View.GONE);
			inputBar.setVisibility(View.GONE);

			break;
		// 隐藏照相选项
		case PHOTO_HIDE:

			inputMoreBt.setSelected(false);

			inputBar.setVisibility(View.VISIBLE);

			break;
		// 显示表情
		case FACE_SHOW:
			inputMoreBt.setSelected(true);

			optionSelectBar.setVisibility(View.GONE);
			faceBar.setVisibility(View.VISIBLE);

			break;
		// 隐藏表情
		case FACE_HIDE:
			inputMoreBt.setSelected(false);

			faceBar.setVisibility(View.GONE);

			break;
		// 显示模板
		case MODULE_SHOW:

			optionSelectBar.setVisibility(View.GONE);

			break;
		// 隐藏模板
		case MODULE_HIDE:
			inputMoreBt.setSelected(false);

			faceBar.setVisibility(View.GONE);

			break;

		// 正常
		default:
			// hideKeyboard();
			resetInputType(true);

			inputMoreBt.setSelected(false);
			faceBar.setVisibility(View.GONE);

			optionSelectBar.setVisibility(View.GONE);

			inputBar.setVisibility(View.VISIBLE);

			break;
		}
	}

}